package com.wuming.house.controller;

import com.wuming.house.core.BusinessException;
import com.wuming.house.core.JsonResult;
import com.wuming.house.model.Member;
import com.wuming.house.service.MemberService;
import com.wuming.house.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by hanfei on 16/4/19.
 */
@Controller
@RequestMapping("/web")
public class IndexController extends BaseController {


    @Autowired
    private MemberService memberService;

    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public String index() {
        return "/main/index";
    }


    @RequestMapping(value = "/home", method = RequestMethod.GET)
    public String home() {
        return "/main/home";
    }


    @ResponseBody
    @RequestMapping(value = "/data", method = RequestMethod.GET)
    public JsonResult data(@RequestParam Integer memberId) {
        Map<String, Object> result = new HashMap<String, Object>();
        Date current = new Date();
        String startTime = DateUtil.dateToString(current, "yyyy-MM-dd");
        String endTime = DateUtil.dateToString(current, "yyyy-MM-dd");
        try {
            Member member = memberService.getMemberById(memberId);
            return new JsonResult(result, "查询首页数据成功.");
        } catch (BusinessException be) {
            return new JsonResult(null, "查询首页数据失败.", false);
        } catch (Exception e) {
            return new JsonResult(null, "查询首页数据失败.", false);
        }
    }

}
